package com.wyzz.hr.action;

import java.io.PrintStream;
import java.util.Map;

import com.wyzz.hr.base.BaseAction;
import com.wyzz.hr.util.DatabaseSysConfigManager;
import com.wyzz.hr.util.SysConfigManager;
import com.wyzz.hr.util.impl.PropertiesFileConfigManager;

public class ConfigSalary extends BaseAction {

	public ConfigSalary() {
		dbConfigManager = DatabaseSysConfigManager.getInstance();
		fileConfigManager = PropertiesFileConfigManager.getInstance();
	}

	public String showConfigSalary() throws Exception {
		if (!hasAuth(961, new int[0])) {
			addErrorInfo("\u5BF9\u4E0D\u8D77\uFF0C\u60A8\u65E0\u6743\u8FDB\u5165\u8BE5\u9875\u9762\uFF01");
			return "noauth";
		} else {
			Map dbMap = dbConfigManager.getProperties();
			sys_salary_tax_min = (String) dbMap.get("sys.salary.tax.min");
			sys_salary_tax_min = SystemConfigInit.getValue(sys_salary_tax_min,
					"2000");
			sys_salary_tax_range = (String) dbMap.get("sys.salary.tax.range");
			sys_salary_tax_range = SystemConfigInit.getValue(
					sys_salary_tax_range,
					"0,500,2000,5000,20000,40000,60000,80000,100000");
			sys_salary_tax_rate = (String) dbMap.get("sys.salary.tax.rate");
			sys_salary_tax_rate = SystemConfigInit.getValue(
					sys_salary_tax_rate,
					"0.05,0.10,0.15,0.20,0.25,0.30,0.35,0.40,0.45");
			sys_salary_config_update = (String) dbMap
					.get("sys.salary.config.update");
			sys_salary_config_update = SystemConfigInit.getValue(
					sys_salary_config_update, "0");
			return "success";
		}
	}

	public String executeSalary() throws Exception {
		if (!hasAuth(961, new int[0])) {
			addErrorInfo("\u5BF9\u4E0D\u8D77\uFF0C\u60A8\u65E0\u6743\u8FDB\u5165\u8BE5\u9875\u9762\uFF01");
			return "noauth";
		}
		try {
			Map dbMap = dbConfigManager.getProperties();
			if (!((String) dbMap.get("sys.salary.tax.min"))
					.equals(sys_salary_tax_min))
				dbConfigManager.setProperty("sys.salary.tax.min",
						sys_salary_tax_min);
			if (!((String) dbMap.get("sys.salary.tax.range"))
					.equals(sys_salary_tax_range))
				dbConfigManager.setProperty("sys.salary.tax.range",
						sys_salary_tax_range);
			if (!((String) dbMap.get("sys.salary.tax.rate"))
					.equals(sys_salary_tax_rate))
				dbConfigManager.setProperty("sys.salary.tax.rate",
						sys_salary_tax_rate);
			if (!((String) dbMap.get("sys.salary.config.update"))
					.equals(sys_salary_config_update))
				dbConfigManager.setProperty("sys.salary.config.update",
						sys_salary_config_update);
			fileConfigManager.saveChange();
		} catch (Exception e) {
			e.printStackTrace();
			System.err.println("Visit  for updating  value error");
			return "input";
		}
		addSuccessInfo("\u85AA\u8D44\u6A21\u5757\u53C2\u6570\u8C03\u6574\u6210\u529F\uFF01");
		return "success";
	}

	public String getSys_salary_tax_min() {
		return sys_salary_tax_min;
	}

	public void setSys_salary_tax_min(String sys_salary_tax_min) {
		this.sys_salary_tax_min = sys_salary_tax_min;
	}

	public String getSys_salary_tax_range() {
		return sys_salary_tax_range;
	}

	public void setSys_salary_tax_range(String sys_salary_tax_range) {
		this.sys_salary_tax_range = sys_salary_tax_range;
	}

	public String getSys_salary_tax_rate() {
		return sys_salary_tax_rate;
	}

	public void setSys_salary_tax_rate(String sys_salary_tax_rate) {
		this.sys_salary_tax_rate = sys_salary_tax_rate;
	}

	public String getSalaryAdjDate() {
		return salaryAdjDate;
	}

	public void setSalaryAdjDate(String salaryAdjDate) {
		this.salaryAdjDate = salaryAdjDate;
	}

	public String getSalaryAdjHour() {
		return salaryAdjHour;
	}

	public void setSalaryAdjHour(String salaryAdjHour) {
		this.salaryAdjHour = salaryAdjHour;
	}

	public String getSys_salary_config_update() {
		return sys_salary_config_update;
	}

	public void setSys_salary_config_update(String sys_salary_config_update) {
		this.sys_salary_config_update = sys_salary_config_update;
	}

	private static final long serialVersionUID = 1L;
	private String sys_salary_tax_min;
	private String sys_salary_tax_range;
	private String sys_salary_tax_rate;
	private String sys_salary_config_update;
	private String salaryAdjDate;
	private String salaryAdjHour;
	SysConfigManager dbConfigManager;
	private SysConfigManager fileConfigManager;
}
